package com.lipengqing.framework.interceptor;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Swagger拦截器
 */
@Component
public class SwaggerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String requestUri = request.getRequestURI();
        if (requestUri.contains("swagger-ui") || requestUri.contains("/tool/swagger")) { // 若依swagger接口/tool/swagger也会重定向到swagger，所以也要屏蔽
            response.sendRedirect("/404"); // 可以重定向到自定义的错误页面
            return false;
        }
        return true;
    }
}